local jiewei = fk.CreateSkill{
  name = "est__jiewei"
}
local function getTrueSkills(player)
  local skills = {}
  for _, s in ipairs(player.player_skills) do
    if not (s.attached_equip or s.name[#s.name] == "&" or s.name == "m_feiyang" or s.name == "m_bahu" or s.name:startsWith("&")) then
      table.insertIfNeed(skills, s.name)
    end
  end
  return skills
end

local jieweiEffect = {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
      if not player.dead and player:hasSkill(self) then
          if event == fk.DamageCaused and target == player then 
              return #getTrueSkills(player) < #getTrueSkills(data.to) and data.to ~= player
          end
          if event == fk.Damaged and target == player and table.every(player.room.alive_players, function(p) return not p.dying end) and not player.dead then
              return #getTrueSkills(player) < #getTrueSkills(data.from) and data.from ~= player
          end
      end
  end,
  on_cost = function(self, event, target, player, data)
      if event == fk.DamageCaused and not player.dead and player:hasSkill(self) and player.room:askForSkillInvoke(player, self.name, nil, "jiewei-p1") then
          return true
      end
      if event == fk.Damaged and not player.dead and player:hasSkill(self) and player.room:askForSkillInvoke(player, self.name, nil, "jiewei-p2") then
          return true
      end
  end,
  on_use = function(self, event, target, player, data)
      local room = player.room
      if event == fk.DamageCaused and target == player then
          local to = data.to
          if to.dead then return end
          data.damage = data.damage + 1
          if not player.dead then
              room:changeMaxHp(player, -1)
              if player.dead then return end
              player:drawCards(2)
          end
      end
      if event == fk.Damaged and target == player and table.every(player.room.alive_players, function(p) return not p.dying end) and not player.dead then
          local from = data.from
          local slash = Fk:cloneCard("fire__slash")
          room:loseHp(player, 1, self.name)
          if not (player:prohibitUse(slash) or player:isProhibited(from, slash)) then
              room:useCard({
                  from = player.id,
                  tos = {{from.id}},
                  card = slash,
                  extraUse = true,
                })
          end
      end
  end,
}
jiewei:addEffect(fk.DamageCaused, jieweiEffect)
jiewei:addEffect(fk.Damaged, jieweiEffect)
Fk:loadTranslationTable{
  ["est__jiewei"] = "芥威",
  [":est__jiewei"] = "当你对其他角色造成伤害时，若其技能数大于你，你可以令此伤害+1，然后你减1点体力上限并摸两张牌；当你受到其他角色造成的伤害后，若其技能数大于你，你可以失去1点体力，视为对其使用一张【火杀】。",
  ["jiewei-p1"] = "你可以发动芥威，令此伤害+1",
  ["jiewei-p2"] = "你可以发动芥威，对伤害来源使用一张【火杀】。",
}
return jiewei